home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / xwinc100.zip / CONTRIB-.00 / CONTRIB- / contrib / examples / Xaw / xtext.c < prev    next >
C/C++ Source or Header  |  1991-05-16  |  5KB  |  162 lines

  1. /*
  2.  * xtext.c
  3.  *
  4.  * This an example of how to use the Text and Paned widgets.
  5.  *
  6.  * November 14, 1989 - Chris D. Peterson 
  7.  */
  8.  
  9. /*
  10.  * $XConsortium: xtext.c,v 1.16 91/05/16 14:56:23 swick Exp $
  11.  *
  12.  * Copyright 1989 Massachusetts Institute of Technology
  13.  *
  14.  * Permission to use, copy, modify, distribute, and sell this software and its
  15.  * documentation for any purpose is hereby granted without fee, provided that
  16.  * the above copyright notice appear in all copies and that both that
  17.  * copyright notice and this permission notice appear in supporting
  18.  * documentation, and that the name of M.I.T. not be used in advertising or
  19.  * publicity pertaining to distribution of the software without specific,
  20.  * written prior permission.  M.I.T. makes no representations about the
  21.  * suitability of this software for any purpose.  It is provided "as is"
  22.  * without express or implied warranty.
  23.  *
  24.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  25.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  26.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  27.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  28.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  29.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  30.  */
  31.  
  32. #include <stdio.h>
  33. #include <X11/Intrinsic.h>
  34. #include <X11/StringDefs.h>
  35.  
  36. #include <X11/Xaw/AsciiText.h>
  37. #include <X11/Xaw/Command.h>
  38. #include <X11/Xaw/Paned.h>
  39.  
  40. #include <X11/Xaw/Cardinals.h>
  41.  
  42. static void ClearText(), PrintText(), Syntax();
  43. static void Syntax();
  44.  
  45. String fallback_resources[] = { 
  46.     "*input:                True",
  47.     "*showGrip:                off",
  48.     "?.?.text.preferredPaneSize:    200", 
  49.     "?.?.text.textSource.editType:    edit",
  50.     "?.?.text.scrollVertical:        whenNeeded",
  51.     "?.?.text.scrollHorizontal:        whenNeeded",
  52.     "?.?.text.autoFill:            on",
  53.     "*clear*label:            Click here to clear the text widget.",
  54.     "*print*label:            Click here to print the text to `stdout'.",
  55.     NULL,
  56. };
  57.  
  58. main(argc, argv)
  59. int argc;
  60. char **argv;
  61. {
  62.     XtAppContext app_con;
  63.     Widget toplevel, paned, clear, print, text;
  64.     Arg args[1];
  65.  
  66.     toplevel = XtAppInitialize(&app_con, "Xtext", NULL, ZERO,
  67.                    &argc, argv, fallback_resources,
  68.                    NULL, ZERO);
  69.  
  70.     /*
  71.      * Check to see that all arguments were processed, and if not then
  72.      * report an error and exit.
  73.      */
  74.  
  75.     if (argc != 1)        
  76.     Syntax(app_con, argv[0]);
  77.  
  78.     paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel, 
  79.                   NULL, ZERO);
  80.  
  81.     clear = XtCreateManagedWidget("clear", commandWidgetClass, paned, 
  82.                   NULL, ZERO);
  83.  
  84.     print = XtCreateManagedWidget("print", commandWidgetClass, paned, 
  85.                   NULL, ZERO);
  86.  
  87.     XtSetArg(args[0], XtNstring, 
  88.          "This is a\ntest.  If this\nhad been an actual\nemergency...");
  89.  
  90.     text = XtCreateManagedWidget("text", asciiTextWidgetClass, paned, 
  91.                  args, ONE);
  92.  
  93.     XtAddCallback(clear, XtNcallback, ClearText, (XtPointer) text);
  94.     XtAddCallback(print, XtNcallback, PrintText, (XtPointer) text);
  95.  
  96.     XtRealizeWidget(toplevel);
  97.     XtAppMainLoop(app_con);
  98. }
  99.  
  100. /*    Function Name: ClearText
  101.  *    Description: This function clears all text out of the text widget.
  102.  *    Arguments: w - *** UNUSED ***
  103.  *                 text_ptr - a pointer to the text widget.
  104.  *                 call_data - *** UNUSED ***.
  105.  *    Returns: none.
  106.  */
  107.  
  108. /* ARGSUSED */
  109. static void
  110. ClearText(w, text_ptr, call_data)
  111. Widget w;
  112. XtPointer text_ptr, call_data;
  113. {
  114.     Widget text = (Widget) text_ptr;
  115.     Arg args[1];
  116.  
  117.     XtSetArg(args[0], XtNstring, "");
  118.     XtSetValues(text, args, ONE);
  119. }
  120.  
  121. /*    Function Name: PrintText
  122.  *    Description: This function clears all text out of the text widget.
  123.  *    Arguments: w - *** UNUSED ***
  124.  *                 text_ptr - a pointer to the text widget.
  125.  *                 call_data - *** UNUSED ***.
  126.  *    Returns: none.
  127.  */
  128.  
  129. /* ARGSUSED */
  130. static void
  131. PrintText(w, text_ptr, call_data)
  132. Widget w;
  133. XtPointer text_ptr, call_data;
  134. {
  135.     Widget text = (Widget) text_ptr;
  136.     Arg args[1];
  137.     String str;
  138.  
  139.     XtSetArg(args[0], XtNstring, &str);
  140.     XtGetValues(text, args, ONE);
  141.  
  142.     fprintf(stdout, "Text String is:\n--------\n%s\n--------\n", str);
  143. }
  144.  
  145. /*    Function Name: Syntax
  146.  *    Description: Prints a the calling syntax for this function to stdout.
  147.  *    Arguments: app_con - the application context.
  148.  *                 call - the name of the application.
  149.  *    Returns: none - exits tho.
  150.  */
  151.  
  152. static void 
  153. Syntax(app_con, call)
  154. XtAppContext app_con;
  155. char *call;
  156. {
  157.     XtDestroyApplicationContext(app_con);
  158.     fprintf( stderr, "Usage: %s \n", call);
  159.     exit(1);
  160. }
  161.  
  162.